14A - Letter - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

from cmath import *
from decimal import *
from operator import index
from re import I
import sys
from tkinter import N
input_ = sys.stdin.readline
def _input(): return map(int, input().split())
def _list(): return list(map(int, input().split()))
 
def solves():
    n,m=_input()
    a=[]
    check=0
    mncol=m
    mxcol=0
    mxrow=0
    mnrow=n
    for i in range(n):
        x=list(input())
        k=x.count('*')
        if (k>=1):
            mxrow=max(mxrow,i)
            mnrow=min(mnrow,i)
            mncol=min(mncol,x.index('*'))
            for j in range(m-1,mncol-1,-1):
                if (x[j]=='*'):
                    mxcol=max(mxcol,j)
                    break
        a.append(x)
        for i in range(mnrow,mxrow+1):
        for j in range(mncol,mxcol+1):
            print(a[i][j],end='')
        print()


t=1
for _ in range(0,t):
        solves()

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pair<ll, int>> vpll;
const ll q=25;
const ll z=0;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    freopen("input.txt","r", stdin);

    int n,m;cin>>n>>m;
    vector<string> vs(n);
    int i1=55,i2=-1,j1=55,j2=-1;
    for(int i=0;i<n;i++){
        cin>>vs[i];
        for(int j=0;j<m;j++){
            if (vs[i][j]=='*'){
                i1=min(i1, i);
                i2=max(i2, i);
                j1=min(j1, j);
                j2=max(j2, j);
            }

        }
    }
    for(int i=i1;i<=i2;i++){
        for(int j=j1;j<=j2;j++){
            cout << vs[i][j];
        }
        cout << endl;
    }






}


Comments

Submit
0 Comments
More Questions

961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers